package com.bawei.jetpackdemo.application;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ProcessLifecycleOwner;

/**
 * @Author : yaotianxue
 * @Time : On 2023/9/11 10:49
 * @Description : App
 */
public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        //注册观察者 感知application的生命周期
//        ApplicationObserver applicationObserver = new ApplicationObserver();
//        ProcessLifecycleOwner.get().getLifecycle().addObserver(applicationObserver);

        //重点********，感知整个项目中所有activity的生命周期：onCreate、onDestory 方便管理所有的activity
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
                Log.d("ytx", "onActivityCreated: "+activity.getLocalClassName());
            }

            @Override
            public void onActivityStarted(@NonNull Activity activity) {

            }

            @Override
            public void onActivityResumed(@NonNull Activity activity) {

            }

            @Override
            public void onActivityPaused(@NonNull Activity activity) {

            }

            @Override
            public void onActivityStopped(@NonNull Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(@NonNull Activity activity) {
                Log.d("ytx", "onActivityDestroyed: "+activity.getLocalClassName());
            }
        });






    }

}

